package com.bysj.yqsht.service.impl;

import com.bysj.yqsht.bean.MatchsAchievements;
import com.bysj.yqsht.bean.MatchsAchievementsExample;
import com.bysj.yqsht.bean.extend.MatchsAchievementsExtend;
import com.bysj.yqsht.dao.MatchsAchievementsMapper;
import com.bysj.yqsht.dao.extend.MatchsAchievementsExtendMapper;
import com.bysj.yqsht.service.IMatchAchievementsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class IMatchsAchievementsServiceImpl implements IMatchAchievementsService {

    @Resource
    private MatchsAchievementsMapper matchAchievementsMapper;
    @Resource
    private MatchsAchievementsExtendMapper matchsAchievementsExtendMapper;

    @Override
    public List<MatchsAchievements> findAll() {
        MatchsAchievementsExample example = new MatchsAchievementsExample();
        return matchAchievementsMapper.selectByExample(example);

    }

    @Override
    public void saveOrUpdate(MatchsAchievements matchAchievements) {
        if(matchAchievements.getId() != null){
            matchAchievementsMapper.updateByPrimaryKey(matchAchievements);

        }else {
            matchAchievementsMapper.insert(matchAchievements);
        }

    }

    @Override
    public void deleteById(long id) {
        matchAchievementsMapper.deleteByPrimaryKey(id);

    }

    @Override
    public List<MatchsAchievementsExtend> findWithAll(int pageNum,int limit) {
        PageHelper.startPage(pageNum,limit);
        MatchsAchievementsExample matchsAchievementsExample = new MatchsAchievementsExample();
        List<MatchsAchievementsExtend> list1 = matchsAchievementsExtendMapper.findWithAll();
        PageInfo<MatchsAchievementsExtend> data = new PageInfo<MatchsAchievementsExtend>(list1);
        return list1;
    }

    @Override
    public List<MatchsAchievementsExtend> findWithAllBy(Long matchId, Long studentId) {
        return matchsAchievementsExtendMapper.findWithAllBy(matchId,studentId);
    }
}
